//
//  ViewController.swift
//  SnapKitTest
//
//  Created by jin on 2024/8/12.
//

import UIKit

//自动布局框架
import SnapKit

class ViewController: UIViewController {
    
    var container: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        
        // MARK: - 控件
        //添加一个根容器
        container = UIView()
        //container.backgroundColor = .red
        view.addSubview(container)
        
        //logo
        let logoView = UIImageView()
        logoView.image = UIImage(named: "Logo")
        container.addSubview(logoView)
        
        // MARK: - 手机号登陆按钮
        container.addSubview(phoneLoginButton)
        
        // MARK: - 登陆按钮
        container.addSubview(loginButton)
        
        // MARK: - 协议
        let agrementLabelView = UILabel()
        //设置标题
        agrementLabelView.text = "登录即表示你同意《用户协议》和《隐私政策》"
        
        //设置字体大小和颜色
        agrementLabelView.font = UIFont.systemFont(ofSize: 12)
        agrementLabelView.textColor = .gray
        
        container.addSubview(agrementLabelView)
        
        
        // MARK: - 约束
        //根容器
        container.snp.makeConstraints { make in
            //正数表示向下
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(16)
            //负数表示向上
            make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom).offset(-16)
            
            make.left.equalTo(view.safeAreaLayoutGuide.snp.left).offset(16)
            make.right.equalTo(view.safeAreaLayoutGuide.snp.right).offset(-16)
        }
        
        // MARK: - logo
        logoView.snp.makeConstraints { make in
            //宽高
            make.width.equalTo(100)
            make.height.equalTo(100)
            
            //距离顶部
            make.top.equalTo(100)
            
            //水平居中
            make.centerX.equalToSuperview()
            
        }
        
        // MARK: - 协议
        agrementLabelView.snp.makeConstraints { make in
            //距离底部
            make.bottom.equalToSuperview()
            
            //水平居中
            make.centerX.equalToSuperview()
        }
        
        // MARK: - 登陆按钮
        loginButton.snp.makeConstraints { make in
            //宽和父窗体一样
            make.width.equalToSuperview()
            make.height.equalTo(42)
            
            //底部
            make.bottom.equalTo(agrementLabelView.snp.top).offset(-30)
        }
        
        // MARK: - 手机号登陆
        phoneLoginButton.snp.makeConstraints { make in
            //宽和父窗体一样
            make.width.equalToSuperview()
            make.height.equalTo(42)
            
            //底部
            make.bottom.equalTo(loginButton.snp.top).offset(-30)
        }
        
    }
    
    @objc func phoneLoginClick(_ s:UIButton) {
        print("点击按钮")
        let controller = SettingController()
        navigationController?.pushViewController(controller, animated: true)
    }
    
    @objc func loginClick(_ s:UIButton) {
        print("点击按钮")
        let controller = LoginController()
        navigationController?.pushViewController(controller, animated: true)
    }

    /// 手机号登录按钮
    /// 这是swift中的懒加载写法
    lazy var phoneLoginButton: UIButton = {
        let button = UIButton(type: .system)
        
        //设置标题
        button.setTitle("手机号登陆", for: .normal)
        
        //设置点击事件
        button.addTarget(self, action: #selector(phoneLoginClick(_:)), for: .touchUpInside)
        
        button.backgroundColor = .red
        
        //圆角大小
        button.layer.cornerRadius = 5
        
        //标题默认颜色
        button.setTitleColor(.white,for: .normal)
        
        //按下文本颜色
        button.setTitleColor(.gray,for: .highlighted)
        
        return button
    }()
    
    
    ///用户名和密码登录
    lazy var loginButton: UIButton = {
        let button = UIButton(type: .system)
        
        //设置标题
        button.setTitle("用户名和密码登录", for: .normal)
        
        //设置点击事件
        button.addTarget(self, action: #selector(loginClick(_:)), for: .touchUpInside)
        
        button.backgroundColor = .clear
        
        //圆角大小
        button.layer.cornerRadius = 21
        
        button.layer.borderWidth = 1
        button.layer.borderColor = UIColor.red.cgColor
        
        //标题默认颜色
        button.setTitleColor(.red,for: .normal)
        
        //按下文本颜色
        button.setTitleColor(.gray,for: .highlighted)
        
        return button
    }()
}

